package org.andao.security.service;

import java.util.List;
import java.util.Map;

import org.andao.core.base.service.BaseService;
import org.andao.core.dao.helper.Page;
import org.andao.core.exception.ServiceException;
import org.andao.core.utils.WrappedRequest;
import org.andao.security.model.Resource;
import org.andao.security.model.Role;
import org.andao.security.model.User;
import org.andao.security.model.UserAdaptor;
import org.andao.security.rest.AuthenticationResult;



/**
 * 用户服务接口. 
 * 
 * @author Marco.hu(hzg139@163.com)
 */
public interface UserService extends BaseService<User> {
			
	/**
	 * 根据用户登录账号获取用户对象
	 * 
	 * @param userName
	 * @return
	 * @throws ServiceException
	 */
	User getUserByLoginId(String userName) throws ServiceException;

	/**
	 * 是否存在该账号的用户
	 * 
	 * @param userName
	 * @return
	 * @throws ServiceException
	 */
	boolean isExistsUser(String userName) throws ServiceException;

	/**
	 * 获取用户的授权资源 
	 * @param username   用户登录名
	 * @param resourceLevel    资源级别. 资源是一个树形结构，资源级别表示该节点所处层级.
	 * @return
	 * @throws ServiceException
	 */
	List<Resource> getUserAuthoritys(String username, int resourceLevel) throws ServiceException;

	/**
	 * 根据条件查找用户
	 * <排除学生>学生在学籍信息里查找
	 * 
	 * @param condition
	 * @param order
	 * @param page
	 * @return
	 * @throws ServiceException
	 */
	Page findUserByCondition(Map<String, Object> condition, Page page) throws ServiceException;
			
	
	/**
	 * 批量删除
	 * @param split
	 */
	void batchCascadeDelete(String[] split);
		
	
	/**
	 * 根据用户ID 获取用户代理，给工作流等外部组件用
	 * @param userId
	 * @return
	 * @throws ServiceException
	 */
	UserAdaptor getUserAdaptor(String userId) throws ServiceException;
	
	/**
	 * 修改用户密码.
	 * @param userId
	 * @param oldPwd
	 * @param newPwd
	 * @throws ServiceException
	 */
	void changedUserPassword(String userId,String oldPwd,String newPwd) throws ServiceException;
	
	/**
	 * 根据ID查找用户的角色列表
	 * @param userId
	 * @return
	 * @throws ServiceException
	 */
	List<Role> findUserRoles(String userId) throws ServiceException;
	
	/**
	 * 验证REST请求是否安全.
	 * @param request
	 * @return
	 */
	AuthenticationResult determineRESTRequest(WrappedRequest request);

	/**
	 * 验证用户名是否重复
	 * @param username
	 * @param resourceid
	 * @return
	 */
	boolean checkDuplicateName(String username, String resourceid);

	/**
	 * 分页查找UserVo,支持unitId in (:unitIdList)
	 * @param condition
	 * @param objPage
	 * @return Page of UserVo
	 * @author Seewo Software - Vick.liu (liuguanglin@cvte.cn)
	 */
	Page findUserBySqlCondition(Map<String, Object> condition, Page objPage);
	
	
}
